package hot_100;

import java.util.HashMap;

public class 两数之和 {
    public static void main(String[] args) {

    }
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int x = 0, y = 0;
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                x = map.get(target - nums[i]);
                y = i;
                break;
            }
            map.put(nums[i], i);
        }
        return new int[]{x, y};
    }
}
